<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <body>
        <ui:composition template="../WEB-INF/facelets/template.xhtml">
            <ui:param name="title" value="Vrångö IF Gym – Användare" />
            <ui:define name="content">
                <h:outputLabel styleClass="header" value="Användare"/>

                <h:dataTable id="users-table" var="user"   
                             value="#{AdminUsers.users}"
                             rowClasses="odd, even"
                             rendered="#{not empty AdminUsers.users}">  

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Användarnamn" styleClass="subheader"/>
                        </f:facet>
                        <h:outputText value="#{user.userName}" escape="false"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Telefon" styleClass="subheader" />
                        </f:facet>
                        <h:outputText value="#{user.contactInfo.phoneNumber}" escape="false"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Mail" styleClass="subheader" />
                        </f:facet>
                        <h:outputText value="#{user.contactInfo.email}" escape="false"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Rättigheter" styleClass="subheader" />
                        </f:facet>
                        <h:form>
                            <h:selectOneMenu valueChangeListener="#{AdminUsersCtrl.permissionsChanged}" converter="PermissionConverter" onchange="submit()" immediate="true" id="permission" value="#{user.permissions}">
                                <f:attribute name="user" value="#{user}" />
                                <f:selectItems value="#{AdminUsers.permissions}"  var="permissions" />
                            </h:selectOneMenu>
                        </h:form>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Ta Bort" styleClass="subheader" />
                        </f:facet>
                        <h:form>
                            <p:commandButton update="users-table" styleClass="commandButton" actionListener="#{AdminUsersCtrl.deleteUser}" action="onAdminUserDelete" value="Ta bort" >
                                <f:attribute name="user" value="#{user}" />
                            </p:commandButton>
                        </h:form>
                    </h:column>
                </h:dataTable>

            </ui:define>
        </ui:composition>
    </body>
</html>